package mysql

import "gorm.io/gorm"

type Order struct {
	gorm.Model
	UserId      int64   `gorm:"type:int;comment:用户id"`
	OrderSn     string  `gorm:"type:char(36);unique;comment:订单号"`
	PayType     int64   `gorm:"type:tinyint(1);default:1;comment:支付类型:1:支付宝,2:微信"`
	PayTime     string  `gorm:"type:datetime(3);comment:支付时间"`
	Amount      float64 `gorm:"type:decimal(10,2);default:0.00;comment:金额"`
	OrderStatus int64   `gorm:"type:tinyint(1);default:1;comment:订单状态:1:待支付;2:已支付;3:已取消;4:已退款;5:已完成"`
}
type OrderGoods struct {
	GoodsId    int64   `gorm:"type:int;comment:商品id"`
	OrderId    int64   `gorm:"type:int;comment:订单id"`
	GoodsName  string  `gorm:"type:varchar(20);comment:商品名称"`
	GoodsPrice float64 `gorm:"type:decimal(10,2);default:0.00;comment:价格"`
	GoodsStock int64   `gorm:"type:int;comment:库存"`
	GoodsCover string  `gorm:"type:varchar(200);not null;comment:封面"`
	//GoodsStatus int64   `gorm:"type:tinyint(1);default:1;comment:状态:1:待出售,2:通过,3:不通过"`
}

func (o *Order) Create() error {
	return Db.Create(&o).Error
}

func (og *OrderGoods) Create() error {
	return Db.Create(&og).Error
}
func (o *Order) UpdateOrderStatus(orderSn string, orderStatus int64) error {
	return Db.Model(&o).Where("order_sn = ?", orderSn).Update("order_status", orderStatus).Error
}
